#include "wscaircraftshtmloverview.h"
using namespace FsxWebService;

//
// List of aircrafts
//
WscAircraftsHtmlOverview::WscAircraftsHtmlOverview(const int port, const QString &serverUrl, const QString &path, QObject *parent) :
    WscRequestHandler(port, serverUrl, path, parent)
{
    // constructor code
}

//
// Service of the web service
//
void WscAircraftsHtmlOverview::service(HttpRequest&, HttpResponse& response) {

    // set some headers
    response.setHeader("Content-Type", "text/html; charset=ISO-8859-1");
    response.setCookie(HttpCookie("wscaircrafts","aircrafts",600));

    // generate response
    // http://qt-project.org/faq/answer/how_can_i_convert_a_qstring_to_char_and_vice_versa
    QString dp = emit WscAircraftsHtmlOverview::signalAircraftsHtmlTable();
    if (dp.isEmpty()) {
        response.write("No aircraft data, connected to FSX? Or maybe FSX is in startup phase or start screen.");
    } else {
        QByteArray ba = dp.toLocal8Bit();
        response.write(ba);
    }
}
